package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.service.admin.impl.SetmealServiceImpl;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {
@Autowired
private SetmealService setmealService;
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> findByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult byPage = setmealService.findByPage(setmealPageQueryDTO);
        return byPage != null?Result.success(byPage):Result.error("sb");
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id查询")
    public Result<SetmealVO> findById(@PathVariable Long id){
        SetmealVO byId = setmealService.findById(id);
        return byId != null? Result.success(byId):Result.error("sb");
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        int row = setmealService.updateSetmeal(setmealDTO);
        return row >0 ?Result.success():Result.error("sb");
    }
    @PostMapping("/status/{status}")
    @ApiOperation("修改启用停售状态")
    public Result updateStatus(@PathVariable Integer status,Long id){
        int row = setmealService.updateStatus(status, id);
        return row >0 ?Result.success():Result.error("sb");
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result delectByIds(@RequestParam List<Long> ids){
        int row = setmealService.delectByIds(ids);
        return row >0 ?Result.success():Result.error("sb");
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        int row = setmealService.addSetmeal(setmealDTO);
        return row >0 ?Result.success():Result.error("sb");
    }
}
